package lesson2;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.function.Consumer;

public class TestVolatile {

    public static void main(String[] args) throws InterruptedException {
        ArrayBlockingQueue<Integer> blockingQueue = new ArrayBlockingQueue(8);
        Producer producer = new Producer(blockingQueue);
        Thread thread = new Thread(producer);
        thread.start();
        Thread.sleep(500);

        lesson2.Consumer consumer = new lesson2.Consumer(blockingQueue);
        while (consumer.needMoreNum()){
            consumer.blockingQueue.take();
        }
        //thread.interrupt();
        producer.flag = true;
        System.out.println("消费者不需要更多数据了。");


    }
}
